<?php
/**
 * @Author: gan
 * @Description:
 * @File:  UploadBase
 * @Version: 1.0.0
 * @Date: 2021/12/27 7:10 下午
 */
declare(strict_types=1);

namespace RX\Component\Upload;

use RX\Component\Upload\Impl\CosImpl;
use RX\Component\Upload\Impl\LocalImpl;
use RX\Component\Upload\Impl\OssImpl;
use RX\Component\Upload\Impl\UploadInterface;
use RX\Enums\CommonEnum;
use RX\Exception\BizException;

final class UploadStaticFactory
{
    /**
     * @param string $type
     * @param array $config
     * @return UploadInterface
     * @throws BizException
     */
    public static function factory(string $type, array $config = []): UploadInterface
    {
        switch ($type) {
            case UploadType::OSS:
                return new OssImpl($config);
            case UploadType::COS:
                return new CosImpl($config);
            case UploadType::LOCAL:
                return new LocalImpl($config);
            default:
                throw new BizException(CommonEnum::class, CommonEnum::INVALID_PARAMS);
        }
    }
}
